/**
 *
 * @author ilya portnyagin iportnyagin@gmail.com
 */

package ru.portnyagin.helpdeskru.model;

import java.io.Serializable;
import java.util.Date;
import java.util.ResourceBundle;
import javax.faces.context.FacesContext;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Version;

@Entity
@Table(name = "Request")
public class Request implements Serializable {
    private static final long serialVersionUID = 1L;
    
    @Id
//    @Basic(optional = false)
//    @NotNull
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID")
    private Long id;

    @JoinColumn(name = "CREATED_BY", referencedColumnName = "ID")
    @ManyToOne(fetch = FetchType.LAZY)
    private UserHD createdBy;
    
    @Column(name = "CREATED_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date createdDate;
        
    
    @Column(name = "DESCRIPTION")
    private String description;
    
    @Lob
    @Column(name = "TEXT")
    private String text;
    
    @JoinColumn(name = "PRIORITY", referencedColumnName = "ID")
    @ManyToOne(fetch = FetchType.LAZY)
    private Priority priority;
    
    
    @JoinColumn(name = "SERVICE_OBJECT", referencedColumnName = "ID")
    @ManyToOne(fetch = FetchType.LAZY)
    private ServiceObject serviceObject;
    
    
    @JoinColumn(name = "PERFOMER", referencedColumnName = "ID")
    @ManyToOne(fetch = FetchType.LAZY)
    private UserHD performer;
    
    
    @JoinColumn(name = "STATE_REQUEST", referencedColumnName = "ID")
    @ManyToOne(fetch = FetchType.LAZY)
    private StateRequest stateRequest;    
    
    @Column(name = "STATE_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date stateDate;
     
    @Version
    @Column(name = "VERSION")
    private Integer version;    


    public Request() {
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public UserHD getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(UserHD createdBy) {
        this.createdBy = createdBy;
    }

    public Date getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(Date createdDate) {
        this.createdDate = createdDate;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public Priority getPriority() {
        return priority;
    }

    public void setPriority(Priority priority) {
        this.priority = priority;
    }
    
    public ServiceObject getServiceObject() {
        return serviceObject;
    }

    public void setServiceObject(ServiceObject serviceObject) {
        this.serviceObject = serviceObject;
    }

    public UserHD getPerformer() {
        return performer;
    }

    public void setPerformer(UserHD performer) {
        this.performer = performer;
    }

    public StateRequest getStateRequest() {
        return stateRequest;
    }

    public void setStateRequest(StateRequest stateRequest) {
        this.stateRequest = stateRequest;
    }

    public Date getStateDate() {
        return stateDate;
    }

    public void setStateDate(Date stateDate) {
        this.stateDate = stateDate;
    }

    public Integer getVersion() {
        return version;
    }

    public void setVersion(Integer version) {
        this.version = version;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (this.id != null ? this.id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Request)) {
            return false;
        }
        Request other = (Request) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return ResourceBundle.getBundle("property", 
                FacesContext.getCurrentInstance().getViewRoot().getLocale()).
                getString("request") 
                + id.toString(); 
    }
    
}
